package com.qf.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.entity.R;
import com.qf.entity.Room;
import com.qf.entity.RoomPrice;
import com.qf.service.RoomPriceService;
import com.qf.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Room)表控制层
 *
 * @author makejava
 * @since 2020-09-15 15:55:53
 */
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;
    @Autowired
    private RoomPriceService roomPriceService;

    @RequestMapping("/insert")
    public R<Boolean> insert(@RequestBody Room room){
        return new R<Boolean>().setData(roomService.save(room));
    }

    @RequestMapping("/list/{hid}")
    public R<List<Room>> list(@PathVariable Integer hid){
        QueryWrapper<Room> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("hid", hid);
        List<Room> list = roomService.list(queryWrapper);
        return new R<List<Room>>().setData(list);
    }

    /**
     * 获得房间价格
     * @return
     */
    @RequestMapping("/getPirce")
    public R<List<RoomPrice>> getRoomPrice(@RequestParam Integer rid){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("rid", rid);
        List<RoomPrice> list = roomPriceService.list(queryWrapper);
        return new R<List<RoomPrice>>().setData(list);
    }

    /**
     * 修改客房价格
     * @return
     */
    @RequestMapping("/updateprice")
    public R<Boolean> updatePrice(@RequestBody RoomPrice roomPrice){
        boolean flag = roomPriceService.updateById(roomPrice);
        return new R<Boolean>().setData(flag);
    }

    /**
     * 根据roomid查询room信息
     * @param rid
     * @return
     */
    @RequestMapping("/getRoomById")
    public R<Room> getRoomById(@RequestParam Integer rid){
        Room room = roomService.getById(rid);
        return new R<Room>().setData(room);
    }
}